const WITHDRAW_STATUS = {
  'problems': '有问题',
  'cancelled': '已取消',
  'rejected': '被拒绝',
  'pending': '等待中',
  'accepted': '已通过',
  'retrieved': '已接收'
}
const WITHDRAW_STATUS_COLOR = {
  'problems': 'danger',
  'cancelled': 'info',
  'rejected': 'info',
  'pending': 'warning',
  'accepted': '',
  'retrieved': 'success'
}

export default {
  OfficerWithdraw: {
    entity: { name: 'Withdraw', prefix: `officer` },
    list: {
      disabled_actions: ['new', 'lines'],
      query: {
        '@order': 'entity.id|DESC'
      },
      list_filter: {
        status: Object.assign({ __label: '状态' }, WITHDRAW_STATUS),
        beforeCreatedTime: {
          expression: 'entity.getCreatedTime() >= datetime.get(":value  00:00:00")',
          label: '开始时间',
          type: 'date'
        },
        afterCreatedTime: {
          expression: 'entity.getCreatedTime() < datetime.get(":value 23:59:59")',
          label: '结束时间',
          type: 'date'
        }
      },
      list_display: [
        'id',
        {
          property: 'user',
          label: '真实姓名/员工',
          component: {
            props: ['data'],
            data() {
              return {
                account: '',
                staffName: '/无'
              }
            },
            created() {
              this.axios.get(`/officer/fuiou-accounts/from-user/${this.data.id}`).then((res) => {
                console.log('account', res.data)
                if (res.data !== false) {
                  this.account = res.data.name
                } else {
                  this.account = '无权查看'
                }
              })
              this.axios.get(`/officer/staffs`, { params: { '@filter': `entity.getUser().getId() == ${this.data.id}` }}).then((res) => {
                console.log('staff', res.data)
                if (res.data.length > 0) {
                  this.staffName = `/${res.data[0].name}`
                }
              })
            },
            render(h) {
              return <div>{this.account}{this.staffName}</div>
            }
          }
        },
        'user',
        'batchNo',
        'amount',
        {
          property: 'status',
          component: {
            props: ['data'],
            data() {
              return {
                status: WITHDRAW_STATUS,
                color: WITHDRAW_STATUS_COLOR
              }
            },
            render(h) {
              return <el-tag type={this.color[this.data]} effect='plain'>{this.status[this.data]}</el-tag>
            }
          }
        },
        'createdTime'
      ]
    },
    form: {
      fields: '__all__'
    }
  }
}

